import { ref } from 'vue'
import PageProgress from './PageProgress.js'
export default class Book {
  constructor(options = {}) {
    this.name = options.name || ''
    this.page = ref(options.page || 0)
    this.progress = new PageProgress({
      total: this.page.value
    })
  }
  toJSON() {
    return {
      name: this.name,
      page: this.page.value,
      progress: this.progress.toJSON()
    }
  }
  fromJSON(json) {
    this.name = json.name
    this.page.value = json.page || 0
    this.progress = new PageProgress({
      total: this.page.value
    }).fromJSON(json.progress)
    return this
  }
}
